package org.zoomdev.zoom.ioc;

import java.lang.reflect.Type;
import java.util.Collection;
import java.util.function.Predicate;

public interface Ioc {

    /**
     * 注入依赖
     *
     * @param result
     */
    void inject(Object result);


    void setEnhancer(IocEnhancer enhancer);

    <T> T fetch(Type type, String name);

    <T> T fetch(Type type);

    /**
     * 保证取出，否则出错
     *
     * @param key
     * @param <T>
     * @return
     */
    <T> T fetch(IocKey key);

    /**
     * 不一定有值
     *
     * @param key
     * @param <T>
     * @return
     */
    <T> T get(IocKey key);

    void addFactory(IocFactory factory);

    void insertFactory(IocFactory factory);

    void replaceFactory(Class oldFactory, IocFactory factory);

    void put(IocKey key, Object data);


    /**
     * 获取全部依赖(构建依赖)
     *
     * @param key
     * @return
     */
    Collection<IocKey> getDependencies(IocKey key);

    /**
     * 获取相关所有链接的key，包含构建函数、注入项目、aop的依赖等
     *
     * @param key
     * @return
     */
    Collection<IocKey> getLinked(IocKey key);

    /**
     * 查找相关
     *
     * @param type
     * @return
     */
    Collection<IocKey> find(Class<?> type);

    /**
     * 获取所有符合type的对象
     *
     * @return
     */
    Collection<Object> gets(Class<?> type);

    Collection<Object> gets(Predicate<Object> predicate);
}
